<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ThermalLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ThermalLogController extends AdminController
{
    /**
     * Make a grid builder.
     * 热成像设备日志
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ThermalLog(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('deviceId');
            $grid->column('max','最大值');
            $grid->column('min','最小值');
            $grid->column('average','平均值');
            $grid->column('pushtime','上传时间')->display(function($pushtime) {
                return date('Y-m-d H:i:s',$pushtime);
            });
            $grid->column('created_at','接收时间');
            // $grid->column('updated_at');
            $grid->column('type','类型')->using(['0'=>'数据  ','1'=>'报警']);
            $grid->column('content','报警内容');
            $grid->column('created_at','接收时间');
            // $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('type', '类型', ['数据', '报警']);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ThermalLog(), function (Show $show) {
            $show->field('id');
            $show->field('id');
            $show->field('deviceId');
            $show->field('max');
            $show->field('min');
            $show->field('average');
            $show->field('pushtime');
            $show->field('created_at');
            $show->field('updated_at');
            $show->field('type');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ThermalLog(), function (Form $form) {
            $form->display('id');
            $form->text('deviceId');
            $form->text('max');
            $form->text('min');
            $form->text('average');
            $form->text('pushtime');
            $form->text('created_at');
            $form->text('updated_at');
            $form->text('type');
            $form->text('content');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
